﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using JCodeGen;
using JUtil;


namespace JCodeGen.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                GenerateDO();
                //GenerateGRV();
                //GenerateODS();
            }
            catch (Exception ex)
            {
            	Log.ReportError(ex);
            }
        }

        private static void GenerateDO()
        {
            string filename = string.Empty;

            DatabaseMode databaseMode = DatabaseMode.OleDb;
            string connectionString = "Provider=Microsoft.JET.OLEDB.4.0; data source=" + @"E:\GoogleProjectHosting\jelly-asp-net-sample\src\sample\App_Data\NorthWind.mdb";
            string SelectSQL = "SELECT * FROM CUSTOMERS";
            string DataObjectTypeName = "TheDataObjectTypeName";

            CodeGenFileTypes fileType = CodeGenFileTypes.vb;

            CodeGenBase generator = new DataObjectGenerator(
                                        databaseMode,
                                        connectionString,
                                        SelectSQL,
                                        DataObjectTypeName,
                                        fileType);

            filename = getFilePath(typeof(DataObjectGenerator), fileType);
            generator.Generate(filename, fileType);
        }

        private static void GenerateGRV()
        {
            string filename = string.Empty;

            string GRV_ID = "TheGRV";
            string ODS_ID = "TheObjectDataSource";
            string PageSize = "5";

            CodeGenBase generator = new GridViewGenerator(
                                        GRV_ID,
                                        ODS_ID,
                                        PageSize);

            filename = getFilePath(typeof(GridViewGenerator), CodeGenFileTypes.aspx);
            generator.Generate(filename, CodeGenFileTypes.aspx);

            filename = getFilePath(typeof(GridViewGenerator), CodeGenFileTypes.cs);
            generator.Generate(filename, CodeGenFileTypes.cs);
        }

        private static void GenerateODS()
        {
            string filename = string.Empty;

            string ODS_ID = "TheObjectDataSource";
            string ODS_TYPE = "TheDataObjectOperator";
            string DS_TYPE = "TheDataObject";

            CodeGenBase generator = new ObjectDataSourceGenerator(
                                        ODS_ID,
                                        ODS_TYPE,
                                        DS_TYPE);

            filename = getFilePath(typeof(ObjectDataSourceGenerator), CodeGenFileTypes.aspx);
            generator.Generate(filename, CodeGenFileTypes.aspx);

            filename = getFilePath(typeof(ObjectDataSourceGenerator), CodeGenFileTypes.cs);
            generator.Generate(filename, CodeGenFileTypes.cs);
        }
      
        private static string getFilePath(Type type, CodeGenFileTypes filetype)
        {
            string directory = @"E:\GoogleProjectHosting\jelly-util-codegen\src\JCodeGen\outcome";
            string filepath = string.Format(@"{0}\{1}.{2}", directory, type.Name, filetype.ToString());
            return filepath;
        }

    }
}
